<template>
	<view class="container">
		<view class="layout">
			<view class="empty" v-if="!state.list.length">
				<image src="@/static/images/empty.png"></image>
				<view class="empty-tips">您还没有补货记录</view>
				<view class="empty-tips">您还没有补货记录，请前去申请～</view>
			</view>
			<view class="list" v-else>
				<view class="list-box" v-for="(item, index) in state.list" :key="index">
					<view class="top" @click="gotoPage(item)">
						<view class="title">补货数量：{{ item.num }}</view>
						<view class="flexjus">
							<view class="time">{{ item.created_at }}</view>
							<view class="status">{{ item.status_text }}</view>
						</view>
					</view>
					<view class="footer" v-if="item.status == 2">
						<view class="btn-group-right">
							<view class="btn" @click="chakanwuliu(item)">查看物流</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="bigBtn" @click="gotoPage">+ 申请补货</view>
	</view>
</template>

<script setup>
import { reactive } from 'vue';
import { get } from '@/request/index.js';
import { onShow } from '@dcloudio/uni-app';

onShow(async () => {
	await getListData();
});

const state = reactive({
	list: [],
	page: 1,
	totalPage: 1
});
//获取申请补货记录
const getListData = async () => {
	const res = await get('agent/change/bu_list', { page: state.page });
	const { code, data } = res;
	if (code == 200) {
		data.data.map((item) => {
			if (item.status == 1) {
				item.status_text = '平台审核中';
			} else if (item.status == 2) {
				item.status_text = '平台审核通过';
			} else if (item.status == 3) {
				item.status_text = '平台审核拒绝';
			}
		});
		state.list = data.data;
		state.totalPage = data.last_page;
	}
};
//申请补货跳页面和查看补货状态
const gotoPage = (item) => {
	if (item?.num) {
		uni.navigateTo({
			url: `/pages/buhuoStatus/buhuoStatus?status=${item.status}&num=${item.num}&time=${item.created_at}&expressno=${item.expressno}`
		});
	} else {
		uni.navigateTo({
			url: '/pages/buhuoStatus/buhuoStatus?status=0'
		});
	}
};
const chakanwuliu = (item) => {
	uni.navigateTo({
		url: `/pages/wuliudetail/wuliudetail?expressno=${item.expressno}`
	});
};
</script>

<style scoped lang="scss">
.list {
	padding-bottom: 80rpx;
}
</style>
